package com.impress.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Matrix.ScaleToFit;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.impress.R;
import com.impress.Utility;
import com.impress.model.Item;

public class BannerItemsAdapter extends BaseItemsListAdapter {

	public BannerItemsAdapter(Context context, List<Item> items) {
		super(context, items);
		
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Item item = mItems.get(position);
		ViewHolder holder;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_banner, null);
			holder.layout =(ImageView) convertView.findViewById(R.id.item_banner_layout);
			holder.textView = (TextView)convertView.findViewById(R.id.item_summary_title);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder)convertView.getTag();
		}
		holder.textView.setText(Utility.trimString(item.getTitle(), 50));
		if(!Utility.EmptyString(item.getPreviewImg())){
			Bitmap img = BitmapFactory.decodeFile(item.getPreviewImg().replace("file://", ""));
			if(img!=null && img.getHeight()*img.getWidth()>50*50){
//			Bitmap bitmap = Utility.resizeImage(img, 120, 120);
			holder.layout.setImageBitmap(img);
			holder.layout.setScaleType(ScaleType.CENTER_CROP);
			}
		}
		return convertView;
	}

	class ViewHolder{
		TextView textView;
		ImageView layout;
	}

}
